package com.finer.controller.goods;

import com.finer.dto.warehouse.GoodsPageDTO;
import com.finer.entity.ResponseMessage;
import com.finer.entity.document.FinerGoods;
import com.finer.remote.warehouse.FinerGoodsRemote;
import com.finer.service.goods.WarehouseGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangenhao
 * @className WarehouseGoodsController
 * @description 商品管理请求控制类
 * @date 2024-10-22 下午2:12
 **/
@RestController
@RequestMapping("/goods")
@Slf4j
@CrossOrigin
public class WarehouseGoodsController implements FinerGoodsRemote {

    @Autowired
    private WarehouseGoodsService warehouseGoodsService;

    /**
     * @return com.finer.entity.ResponseMessage
     * @description 查询商品分页
     * @date 2024/10/22 下午7:21
     * @Param goodsPageDTO:
     **/
    @GetMapping("/page")
    public ResponseMessage getGoodsPage(GoodsPageDTO goodsPageDTO) {
        log.info("WarehouseGoodsController getGoodsPage goodsPageDTO:{}", goodsPageDTO);
        ResponseMessage rs = warehouseGoodsService.getGoodsPage(goodsPageDTO);
        log.info("WarehouseGoodsController getGoodsPage rs:{}, goodsPageDTO:{}", rs, goodsPageDTO);
        return rs;
    }

    /**
     * @return com.finer.entity.ResponseMessage
     * @description 新增商品
     * @date 2024/10/22 下午7:21
     * @Param finerGoods:
     **/
    @PostMapping("/add")
    public ResponseMessage addGoods(@RequestBody FinerGoods finerGoods) {
        log.info("WarehouseGoodsController addGoods finerGoods:{}", finerGoods);
        ResponseMessage rs = warehouseGoodsService.addGoods(finerGoods);
        log.info("WarehouseGoodsController addGoods rs:{}, finerGoods:{}", rs, finerGoods);
        return rs;
    }

    /**
     * @return com.finer.entity.ResponseMessage
     * @description 根据id查询商品
     * @date 2024/10/22 下午7:49
     * @Param id:
     **/
    @GetMapping("/{id}")
    public ResponseMessage getGoodsById(@PathVariable Integer id) {
        log.info("WarehouseGoodsController getGoodsById id:{}", id);
        ResponseMessage rs = warehouseGoodsService.getGoodsById(id);
        log.info("WarehouseGoodsController getGoodsById rs:{}, id:{}", rs, id);
        return rs;
    }

    /**
     * @return com.finer.entity.ResponseMessage
     * @description 修改商品
     * @date 2024/10/22 下午7:49
     * @Param finerGoods:
     **/
    @PutMapping("/update")
    public ResponseMessage updateGoods(@RequestBody FinerGoods finerGoods) {
        log.info("WarehouseGoodsController updateGoods finerGoods:{}", finerGoods);
        ResponseMessage rs = warehouseGoodsService.updateGoods(finerGoods);
        log.info("WarehouseGoodsController updateGoods rs:{}, finerGoods:{}", rs, finerGoods);
        return rs;
    }

    /**
     * @return com.finer.entity.ResponseMessage
     * @description 删除商品
     * @date 2024/10/22 下午8:10
     * @Param id:
     **/
    @DeleteMapping("/delete")
    public ResponseMessage deleteGoods(Integer id) {
        log.info("WarehouseGoodsController deleteGoods id:{}", id);
        ResponseMessage rs = warehouseGoodsService.deleteGoods(id);
        log.info("WarehouseGoodsController deleteGoods rs:{}, id:{}", rs, id);
        return rs;
    }


}
